package com.attendance.controller;

import com.attendance.common.R;
import com.attendance.entity.Employee;
import com.attendance.entity.Kpi;
import com.attendance.service.EmployeeService;
import com.attendance.service.KpiService;
import com.attendance.util.JwtUtil;
import com.attendance.util.Md5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/emp")
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;
    @Autowired
    KpiService kpiService;


    //返回类型待更换

    @PostMapping("/login")
    public R login(@RequestBody Employee employee) {
        Employee loginUser = employeeService.getByName(employee.getUsername());
        if (loginUser.getPassword().equals(Md5Utils.hash(employee.getPassword()))) {
            String token = JwtUtil.creatToken(loginUser.getId());
            System.out.println(token);
            return R.success(token);
        } else {
            return R.error("登陆失败");
        }


    }
    @PostMapping("/kpi")
    public R kpi(@RequestBody Kpi kpi){
       kpiService.savaKpi(kpi);
        return null;
    }
}
